<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">
<style>
    #commentForm .main-container .short_table_list tbody{min-height: unset!important;}
</style>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>编辑费用收取</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container" style="padding-bottom: 500px!important;">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>申请人信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowuser" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请部门</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowdept" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>工程信息</span><span onclick="go_to_engin_xiang()" class="colorlan" style="float: right;margin-right: 12px">查看工程概况</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程名称</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="enginid">
                            <input type="text" id="enginid_name" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="engin_number" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">业务归属</label>
                        <div class="layui-input-block">
                            <input type="text" id="engin_gui_unit_name" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程管理文件汇编</label>
                        <div class="layui-input-block">
                            <input type="text" id="engin_neiname" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程负责人</label>
                        <div class="layui-input-block">
                            <input type="text" id="engin_gofuer" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">负责人联系电话</label>
                        <div class="layui-input-block">
                            <input type="text" id="engin_gofutel" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>本工程回款资金池信息（单位：元）</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <table class="layui-table chuantable" lay-size="sm">
                        <thead>
                        <tr>
                            <th>累计工程回款</th>
                            <th>累计工程付款</th>
                            <th>累计已收取</th>
                            <th>本工程回款可用余额</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody">
                        <tr>
                            <td><span id="engin_hougonghuimoney"></span></td>
                            <td><span id="engin_hougongzhimoneyquben"></span></td>
                            <td><span id="engin_hougonghuikoufee"></span></td>
                            <td><span id="engin_hougonghuikeyong"></span></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>



            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>本次回款信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">款项摘要</label>
                        <div class="layui-input-block">
                            <input type="text" id="zhai" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">款项类型</label>
                        <div class="layui-input-block">
                            <div id="shougonglei"></div>
                            <input type="text" id="shougonglei_name" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">到账金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="money" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计工程回款含本次(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="leimoney" placeholder="自动计算" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">到账方式</label>
                        <div class="layui-input-block">
                            <input type="text" id="incdaotype_name" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">到账账户</label>
                        <div class="layui-input-block">
                            <input type="text" id="accid_name" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">到账日期</label>
                        <div class="layui-input-block">
                            <input type="text" id="dt" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">本次回款占用销项票金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="xiaofee" id="xiaofee" placeholder="明细自动合计" readonly autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>

        <div class="block-generic list_info">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>关联销项票明细</span></div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>发票号码</th>
                            <th>受票单位</th>
                            <th>发票类型</th>
                            <th>价税合计(元)</th>
                            <th>已回款金额(元)</th>
                            <th>待回款金额(元)</th>
                            <th>本次回款占用开票金额(元)</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>收取信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>本次回款是否收取</label>
                        <div class="layui-input-block">
                            <input type="text" id="iskou" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>选择本次收取款项类型</label>
                        <div class="layui-input-block">
                            <div class="radio-block">
                                <input type="checkbox" name="koulei" lay-filter="koulei" lay-skin="primary" value="fuwu" title="待收取劳务分包服务费">
                                <input type="checkbox" name="koulei" lay-filter="koulei" lay-skin="primary" value="shuifei" title="待收取税款(含利息)">
                                <input type="checkbox" name="koulei" lay-filter="koulei" lay-skin="primary" value="gongjie" title="待收取工程负责人借款(含利息)">
                                <input type="checkbox" name="koulei" lay-filter="koulei" lay-skin="primary" value="kuaifei" title="待收取快递费">
                                <input type="checkbox" name="koulei" lay-filter="koulei" lay-skin="primary" value="qifei" title="直接收取">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">本次收取合计(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="koufee" id="koufee" placeholder="明细自动合计" readonly autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">累计收取合计(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="leikoufee" placeholder="自动计算" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
        </div>




        <div class="block-generic layui-hide fuwu_list_info">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="11">
                    <div class="opt-btn-group">
                        <div><span>收取明细-待收取劳务分包服务费</span></div>
                        <div>
                            <button type="button" onclick="choose_koulei_fuwu()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">选择待扣劳务分包服务费</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>款项类型</th>
                            <th>费用所属工程名称</th>
                            <th><text>*</text>本次收取(元)</th>
                            <th>收取性质</th>
                            <th>收取标准</th>
                            <th>款项说明</th>
                            <th>合同价(元)</th>
                            <th>工程结算金额(元)</th>
                            <th>劳务分包服务费率(%)</th>
                            <th>累计应收取(元)</th>
                            <th>累计已收取(元)</th>
                            <th>待收取(元)</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="fuwu_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

        <div class="block-generic layui-hide shuifei_list_info">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="12">
                    <div class="opt-btn-group">
                        <div><span>收取明细-待收取税款(含利息)</span></div>
                        <div>
                            <button type="button" onclick="choose_koulei_shuifei()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">选择待扣税款及利息</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>款项类型</th>
                            <th>费用所属工程名称</th>
                            <th><text>*</text>本次收取(元)</th>
                            <th>收取性质</th>
                            <th>收取标准</th>
                            <th>款项说明</th>
                            <th>税款保证金承诺书名称</th>
                            <th>申请日期</th>
                            <th>销项票开票金额(元)</th>
                            <th>开票日期</th>
                            <th>税款保证金金额((元)</th>
                            <th>收取状态</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="shuifei_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

        <div class="block-generic layui-hide gongjie_list_info">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="13">
                    <div class="opt-btn-group">
                        <div><span>收取明细-待收取工程负责人借款(含利息)</span></div>
                        <div>
                            <button type="button" onclick="choose_koulei_gongjie()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">选择负责人待还借款</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>款项类型</th>
                            <th><text>*</text>利息优惠(元)</th>
                            <th><text>*</text>本次收取本金(元)</th>
                            <th><text>*</text>本次收取利息(元)</th>
                            <th><text>*</text>本次收取合计(元)</th>
                            <th>收取性质</th>
                            <th>收取标准</th>
                            <th>款项说明</th>
                            <th>合同编号</th>
                            <th>出借方</th>
                            <th>放款到账金额(元)</th>
                            <th>放款日期</th>
                            <th>借款周期数</th>
                            <th>待还本金(元)</th>
                            <th>待还利息(元)</th>
                            <th>待还合计(元)</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="gongjie_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

        <div class="block-generic layui-hide kuaifei_list_info">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="14">
                    <div class="opt-btn-group">
                        <div><span>收取明细-待收取快递费</span></div>
                        <div>
                            <button type="button" onclick="choose_koulei_kuaifei()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">选择待扣快递费</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>款项类型</th>
                            <th>费用所属工程名称</th>
                            <th><text>*</text>本次收取(元)</th>
                            <th>收取性质</th>
                            <th>收取标准</th>
                            <th>款项说明</th>
                            <th>收寄类型</th>
                            <th>运单号</th>
                            <th>收寄日期</th>
                            <th>付款方式</th>
                            <th>快递费用(元)</th>
                            <th>收取状态</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="kuaifei_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

        <div class="block-generic layui-hide qifei_list_info">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="15">
                    <div class="opt-btn-group">
                        <div><span>收取明细-直接收取</span></div>
                        <div>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_add_row">插入行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>款项类型</th>
                            <th>费用所属工程名称</th>
                            <th><text>*</text>本次收取(元)</th>
                            <th><text>*</text>收取性质</th>
                            <th>收取标准</th>
                            <th>款项说明</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="qifei_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    function choose_koulei_fuwu(){
        var enginid = $("#enginid").val() || 0;
        openPage('../hou_gonghui/koulei_fuwu.php?page=hou_gonghui&choose_type=checkbox&enginid='+enginid,'80%','80%');
    }
    function choose_koulei_shuifei(){
        var enginid = $("#enginid").val() || 0;
        var daodt = $("#dt").val();
        openPage('../hou_gonghui/koulei_shuifei.php?page=hou_gonghui&choose_type=checkbox&enginid='+enginid+'&daodt='+daodt,'80%','80%');
    }
    function choose_koulei_gongjie(){
        var enginid = $("#enginid").val() || 0;
        var daodt = $("#dt").val();
        openPage('../hou_gonghui/koulei_gongjie.php?page=hou_gonghui&choose_type=checkbox&enginid='+enginid+'&daodt='+daodt,'80%','80%');
    }
    function choose_koulei_kuaifei(){
        var enginid = $("#enginid").val() || 0;
        openPage('../hou_gonghui/koulei_kuaifei.php?page=hou_gonghui&choose_type=checkbox&enginid='+enginid,'80%','80%');
    }



    function choose_engin_one(obj){
        var enginid = $("#enginid").val() || 0;
        var domkey = $(obj).parents('tr').index();
        openPage('../public/choose_engin.php?page=hou_gonghui_one'+'&benenginid='+enginid+'&domkey='+domkey,'80%','80%');
    }



    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_hou_gonghui_kou, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;
                $("#flowuser").val(data.flowuser);
                $("#flowdept").val(data.flowdept);

                var engininfo = res.data.engininfo;
                if(engininfo){
                    $('#enginid').val(engininfo.id);
                    $('#enginid_name').val(engininfo.name);
                    $('#engin_number').val(engininfo.number);
                    $('#engin_gui_unit_name').val(engininfo.gui_unit_name);
                    $('#engin_gofuer').val(engininfo.gofuer);
                    $('#engin_gofutel').val(engininfo.gofutel);
                    if(engininfo.neiinfo){
                        $('#engin_neiname').val(engininfo.neiinfo.name);
                    }
                    $('#engin_hougonghuimoney').text(engininfo.hougonghuimoney);
                    $('#engin_hougongzhimoneyquben').text(engininfo.hougongzhimoneyquben);
                    $('#engin_hougonghuikoufee').text(engininfo.hougonghuikoufee);
                    $('#engin_hougonghuikeyong').text(engininfo.hougonghuikeyong);
                }

                var account = res.data.account;
                if(account){
                    $('#accid_name').val(account.name+'('+account.accnum+')');
                }



                $("#zhai").val(data.zhai);
                $("#money").val(data.money);
                $("#dt").val(data.dt);
                $("#xiaofee").val(data.xiaofee);
                $("#shougonglei_name").val(data.shougonglei_name);

                var engin_hougonghuimoney = parseValidNum(parseFloat($("#engin_hougonghuimoney").text() || 0) || 0);
                var leimoney = parseFloat(engin_hougonghuimoney) + parseFloat(data.money);
                $("#leimoney").val(leimoney);

                $("#incdaotype_name").val(data.incdaotype_name);
                $("#iskou").val(data.iskou);
                $("#explain").val(data.explain);


                var list = res.data.list;
                if(list.length > 0){
                    for (var key in list){
                        var str = '';
                        var nums = parseInt(key)+1;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td><input type="text"  value="'+list[key].nums+'" class="layui-input nums" readonly></td>';
                        str += '<td><input type="text" class="layui-input shouer" value="'+list[key].shouer+'" readonly></td>';
                        str += '<td><input type="text" class="layui-input qianpiaotype_name" value="'+list[key].qianpiaotype_name+'" readonly></td>';
                        str += '<td><input type="number" class="layui-input money" value="'+list[key].money+'" readonly></td>';
                        str += '<td><input type="number" class="layui-input yihuikuan" value="'+list[key].yihuikuan+'" readonly></td>';
                        str += '<td><input type="number" class="layui-input daihuikuan" value="'+list[key].daihuikuan+'" readonly></td>';
                        str += '<td><input type="number" class="layui-input xiaofee" value="'+list[key].xiaofee+'" readonly></td>';
                        str += '</tr>';
                        $("#list_list").append(str);
                    }
                }


                short_table_opt_func('', 1);
                short_table_opt_func('', 11);
                short_table_opt_func('', 12);
                short_table_opt_func('', 13);
                short_table_opt_func('', 14);
                var listAddStr = '';
                listAddStr += '<tr>';
                listAddStr += '<td style="width: 45px">1</td>';
                listAddStr += '<td><div class="houkoulei"></div></td>';
                listAddStr += '<td><input type="text" enginid="0" onclick="choose_engin_one(this)" readonly value="" class="layui-input enginid disabled"></td>';
                listAddStr += '<td><input type="number" class="layui-input koufee"></td>';
                listAddStr += '<td>';
                listAddStr += '<select class="layui-select kouxing">';
                listAddStr += '<option value="">请选择</option>';
                listAddStr += '<option value="实扣">实扣</option>';
                listAddStr += '<option value="暂扣">暂扣</option>';
                listAddStr += '</select>';
                listAddStr += '</td>';
                listAddStr += '<td><input type="text" class="layui-input shoubiao"></td>';
                listAddStr += '<td><input type="text" class="layui-input explain"></td>';
                listAddStr += '</tr>';
                short_table_opt_func(listAddStr, 15, {name:'houkoulei', data:res.data.houkoulei, value:''});



                if(data.iskou == '是'){
                    $(".koushi").removeClass('layui-hide');
                    $("#koufee").val(data.koufee);

                    if(in_array('fuwu', data.kouleiArr)){
                        $(".fuwu_list_info").removeClass('layui-hide');
                        $("input[value='fuwu']").attr('checked', 'checked');

                        var fuwu_list = res.data.fuwu_list;
                        if(fuwu_list.length > 0){
                            for (var key in fuwu_list){
                                var str = '';
                                var nums = parseInt(key)+1;
                                str += '<tr>';
                                str += '<td style="width: 45px">'+nums+'</td>';
                                str += '<td><input type="text" readonly houkoulei="1" value="劳务分包服务费" class="layui-input houkoulei disabled"></td>';
                                str += '<td><input type="text" readonly enginid="'+fuwu_list[key].enginid+'" value="'+fuwu_list[key].name+'" class="layui-input name disabled"></td>';

                                str += '<td><input type="number" class="layui-input koufee" value="'+fuwu_list[key].koufee+'"></td>';
                                str += '<td><input type="text" class="layui-input disabled kouxing" value="实扣" readonly></td>';
                                str += '<td><input type="text" class="layui-input shoubiao" value="'+fuwu_list[key].shoubiao+'"></td>';
                                str += '<td><input type="text" class="layui-input explain" value="'+fuwu_list[key].explain+'"></td>';

                                str += '<td><input type="number" class="layui-input disabled shimoney" value="'+fuwu_list[key].shimoney+'" readonly></td>';
                                str += '<td><input type="number" class="layui-input disabled shijiemoney" value="'+fuwu_list[key].shijiemoney+'" readonly></td>';
                                str += '<td><input type="number" class="layui-input disabled ratefu" value="'+fuwu_list[key].ratefu+'" readonly></td>';
                                str += '<td><input type="number" class="layui-input disabled yingkoufee" value="'+fuwu_list[key].yingkoufee+'" readonly></td>';
                                str += '<td><input type="number" class="layui-input disabled yikoufee" value="'+fuwu_list[key].yikoufee+'" readonly></td>';
                                str += '<td><input type="number" class="layui-input disabled daikoufee" value="'+fuwu_list[key].daikoufee+'" readonly></td>';
                                str += '</tr>';

                                $("#fuwu_list").append(str);
                                update_refresh_row_func()
                            }
                        }
                    }

                    if(in_array('shuifei', data.kouleiArr)){
                        $(".shuifei_list_info").removeClass('layui-hide');
                        $("input[value='shuifei']").attr('checked', 'checked');

                        var shuifei_list = res.data.shuifei_list;
                        if(shuifei_list.length > 0){
                            for (var key in shuifei_list){
                                var str = '';
                                var nums = parseInt(key)+1;
                                str += '<tr>';
                                str += '<td style="width: 45px">'+nums+'</td>';
                                if(shuifei_list[key].houkoulei == 2){
                                    str += '<td><input type="text" readonly houkoulei="2" value="税款保证金" class="layui-input houkoulei disabled"></td>';
                                }else{
                                    str += '<td><input type="text" readonly houkoulei="3" value="税款保证金利息" class="layui-input houkoulei disabled"></td>';
                                }
                                str += '<td><input type="text" readonly value="'+shuifei_list[key].enginname+'" class="layui-input enginname disabled"></td>';

                                str += '<td><input type="number" class="layui-input disabled koufee" value="'+shuifei_list[key].koufee+'" readonly></td>';
                                str += '<td><input type="text" class="layui-input disabled kouxing" value="实扣" readonly></td>';
                                str += '<td><input type="text" class="layui-input shoubiao" value="'+shuifei_list[key].shoubiao+'"></td>';
                                str += '<td><input type="text" class="layui-input explain" value="'+shuifei_list[key].explain+'"></td>';

                                str += '<td><input type="text" readonly shuiid="'+shuifei_list[key].shuiid+'" value="'+shuifei_list[key].name+'" class="layui-input name disabled"></td>';
                                str += '<td><input type="text" class="layui-input disabled shendt" value="'+shuifei_list[key].shendt+'" readonly></td>';
                                str += '<td><input type="number" class="layui-input disabled xiaofee" value="'+shuifei_list[key].xiaofee+'" readonly></td>';
                                str += '<td><input type="text" class="layui-input disabled dt" value="'+shuifei_list[key].dt+'" readonly></td>';
                                str += '<td><input type="number" class="layui-input disabled baofee" value="'+shuifei_list[key].baofee+'" readonly></td>';
                                str += '<td><input type="text" class="layui-input disabled" value="未收取" readonly></td>';
                                str += '</tr>';

                                $("#shuifei_list").append(str);
                                update_refresh_row_func()
                            }
                        }
                    }

                    if(in_array('gongjie', data.kouleiArr)){
                        $(".gongjie_list_info").removeClass('layui-hide');
                        $("input[value='gongjie']").attr('checked', 'checked');

                        var gongjie_list = res.data.gongjie_list;
                        if(gongjie_list.length > 0){
                            for (var key in gongjie_list){
                                var str = '';
                                var nums = parseInt(key)+1;
                                str += '<tr>';
                                str += '<td style="width: 45px">'+nums+'</td>';
                                str += '<td><input type="text" readonly houkoulei="5" value="借款" class="layui-input houkoulei disabled"></td>';

                                str += '<td><input type="number" value="'+gongjie_list[key].youfee+'" class="layui-input youfee"></td>';
                                str += '<td><input type="number" value="'+gongjie_list[key].kouben+'" class="layui-input kouben"></td>';
                                str += '<td><input type="number" value="'+gongjie_list[key].kouli+'" class="layui-input kouli"></td>';
                                str += '<td><input type="number" value="'+gongjie_list[key].koufee+'" disabled class="layui-input koufee disabled"></td>';
                                str += '<td><input type="text" class="layui-input disabled kouxing" value="实扣" readonly></td>';
                                str += '<td><input type="text" class="layui-input shoubiao" value="'+gongjie_list[key].shoubiao+'"></td>';
                                str += '<td><input type="text" class="layui-input explain" value="'+gongjie_list[key].explain+'"></td>';

                                str += '<td><input type="text" readonly tiaoid="'+gongjie_list[key].tiaoid+'" value="'+gongjie_list[key].number+'" class="layui-input number disabled"></td>';
                                str += '<td><input type="text" readonly value="'+gongjie_list[key].chuer+'" class="layui-input chuer disabled"></td>';
                                str += '<td><input type="number" class="layui-input disabled money" value="'+gongjie_list[key].money+'" readonly></td>';
                                str += '<td><input type="text" readonly value="'+gongjie_list[key].daodt+'" class="layui-input daodt disabled"></td>';
                                str += '<td><input type="number" readonly value="'+gongjie_list[key].yueshu_zhan+'" class="layui-input yueshu_zhan disabled"></td>';
                                str += '<td><input type="number" readonly value="'+gongjie_list[key].daihuanbenfee+'" class="layui-input daihuanbenfee disabled"></td>';
                                str += '<td><input type="number" readonly value="'+gongjie_list[key].daihuanlifee+'" class="layui-input daihuanlifee disabled"></td>';
                                str += '<td><input type="number" readonly value="'+gongjie_list[key].daihuanallfee+'" class="layui-input daihuanallfee disabled"></td>';
                                str += '</tr>';

                                $("#gongjie_list").append(str);
                                update_refresh_row_func()
                            }
                        }
                    }

                    if(in_array('kuaifei', data.kouleiArr)){
                        $(".kuaifei_list_info").removeClass('layui-hide');
                        $("input[value='kuaifei']").attr('checked', 'checked');

                        var kuaifei_list = res.data.kuaifei_list;
                        if(kuaifei_list.length > 0){
                            for (var key in kuaifei_list){
                                var str = '';
                                var nums = parseInt(key)+1;
                                str += '<tr>';
                                str += '<td style="width: 45px">'+nums+'</td>';
                                str += '<td><input type="text" readonly houkoulei="4" value="快递费" class="layui-input houkoulei disabled"></td>';
                                str += '<td><input type="text" readonly kuaitype="'+kuaifei_list[key].kuaitype+'" kuaiid="'+kuaifei_list[key].kuaiid+'" value="'+kuaifei_list[key].enginname+'" class="layui-input enginname disabled"></td>';

                                str += '<td><input type="number" value="'+kuaifei_list[key].koufee+'" disabled class="layui-input koufee disabled"></td>';
                                str += '<td><input type="text" class="layui-input disabled kouxing" value="实扣" readonly></td>';
                                str += '<td><input type="text" class="layui-input shoubiao" value="'+kuaifei_list[key].shoubiao+'"></td>';
                                str += '<td><input type="text" class="layui-input explain" value="'+kuaifei_list[key].explain+'"></td>';

                                str += '<td><input type="text" readonly value="'+kuaifei_list[key].kuailei+'" class="layui-input kuailei disabled"></td>';
                                str += '<td><input type="text" readonly value="'+kuaifei_list[key].yunnum+'" class="layui-input yunnum disabled"></td>';
                                str += '<td><input type="text" readonly value="'+kuaifei_list[key].kuaidt+'" class="layui-input kuaidt disabled"></td>';
                                str += '<td><input type="text" readonly value="'+kuaifei_list[key].futype+'" class="layui-input futype disabled"></td>';
                                str += '<td><input type="number" readonly value="'+kuaifei_list[key].kuaifee+'" class="layui-input kuaifee disabled"></td>';
                                str += '<td><input type="text" readonly value="未收取" class="layui-input disabled"></td>';
                                str += '</tr>';

                                $("#kuaifei_list").append(str);
                                update_refresh_row_func()
                            }
                        }
                    }

                    if(in_array('qifei', data.kouleiArr)){
                        $(".qifei_list_info").removeClass('layui-hide');
                        $("input[value='qifei']").attr('checked', 'checked');

                        var qifei_list = res.data.qifei_list;
                        if(qifei_list.length > 0){
                            for (var key in qifei_list){
                                var str = '';
                                var nums = parseInt(key)+1;
                                str += '<tr>';
                                str += '<td style="width: 45px">'+nums+'</td>';
                                str += '<td><div class="houkoulei houkoulei'+nums+'" key="'+nums+'"></div></td>';
                                str += '<td><input type="text" enginid="'+qifei_list[key].enginid+'" onclick="choose_engin_one(this)" readonly value="'+qifei_list[key].enginname+'" class="layui-input enginid disabled"></td>';
                                str += '<td><input type="number" value="'+qifei_list[key].koufee+'" class="layui-input koufee"></td>';
                                str += '<td>';
                                str += '<select class="layui-select kouxing">';
                                str += '<option value="">请选择</option>';
                                if(qifei_list[key].kouxing == '实扣'){
                                    str += '<option value="实扣" selected>实扣</option>';
                                    str += '<option value="暂扣">暂扣</option>';
                                }else if(qifei_list[key].kouxing == '暂扣'){
                                    str += '<option value="实扣">实扣</option>';
                                    str += '<option value="暂扣" selected>暂扣</option>';
                                }else{
                                    str += '<option value="实扣">实扣</option>';
                                    str += '<option value="暂扣">暂扣</option>';
                                }
                                str += '</select>';
                                str += '</td>';
                                str += '<td><input type="text" class="layui-input shoubiao" value="'+qifei_list[key].shoubiao+'"></td>';
                                str += '<td><input type="text" class="layui-input explain" value="'+qifei_list[key].explain+'"></td>';
                                str += '</tr>';
                                $("#qifei_list").append(str);
                                xmselect_list_dan('houkoulei'+nums, res.data.houkoulei, qifei_list[key].houkoulei);
                                update_refresh_row_func()
                            }
                        }
                    }
                }





                public_upload_file_load('upload_files', res.data.files)
                render_from();
                initParseMoney();
            }
        });


        form.on('checkbox(koulei)', function(data){
            var arr = get_checkbox_value('koulei');
            if(in_array('fuwu', arr)){
                $(".fuwu_list_info").removeClass('layui-hide');
            }else{
                $(".fuwu_list_info").addClass('layui-hide');
            }
            if(in_array('shuifei', arr)){
                $(".shuifei_list_info").removeClass('layui-hide');
            }else{
                $(".shuifei_list_info").addClass('layui-hide');
            }
            if(in_array('gongjie', arr)){
                $(".gongjie_list_info").removeClass('layui-hide');
            }else{
                $(".gongjie_list_info").addClass('layui-hide');
            }
            if(in_array('kuaifei', arr)){
                $(".kuaifei_list_info").removeClass('layui-hide');
            }else{
                $(".kuaifei_list_info").addClass('layui-hide');
            }
            if(in_array('qifei', arr)){
                $(".qifei_list_info").removeClass('layui-hide');
            }else{
                $(".qifei_list_info").addClass('layui-hide');
            }
        });

        form.on('submit(add)', function(data){
            data.field.koulei = get_checkbox_value('koulei').join(',');

            var validRes = $("#commentForm").valid();

            if(!validRes){return false;}

            if(data.field.iskou == '是'){
                if(!data.field.koulei){
                    facade.error("请选择本次收取款项类型");return false;
                }
            }

            var fuwu_list = [''];
            try {
                $('#fuwu_list tr').each(function (i) {
                    var enginid = $(this).find('.name').attr('enginid');
                    var houkoulei = $(this).find('.houkoulei').attr('houkoulei');
                    var koufee = $(this).find('.koufee').val();
                    var kouxing = $(this).find('.kouxing').val();
                    var shoubiao = $(this).find('.shoubiao').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(!koufee){
                        throw new Error('第'+index+'行，请输入本次收取');
                    }
                    fuwu_list.push({
                        enginid:enginid,
                        houkoulei:houkoulei,
                        koufee:koufee,
                        kouxing:kouxing,
                        shoubiao:shoubiao,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".fuwu_list_info .listerror").find('span').text(e.message);
                $(".fuwu_list_info .listerror").show();
                return false;
            }
            $(".fuwu_list_info .listerror").hide();
            data.field.fuwu_list = fuwu_list;



            var shuifei_list = [''];
            try {
                $('#shuifei_list tr').each(function (i) {
                    var shuiid = $(this).find('.name').attr('shuiid');
                    var houkoulei = $(this).find('.houkoulei').attr('houkoulei');
                    var koufee = $(this).find('.koufee').val();
                    var kouxing = $(this).find('.kouxing').val();
                    var shoubiao = $(this).find('.shoubiao').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;

                    shuifei_list.push({
                        shuiid:shuiid,
                        houkoulei:houkoulei,
                        koufee:koufee,
                        kouxing:kouxing,
                        shoubiao:shoubiao,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".shuifei_list_info .listerror").find('span').text(e.message);
                $(".shuifei_list_info .listerror").show();
                return false;
            }
            $(".shuifei_list_info .listerror").hide();
            data.field.shuifei_list = shuifei_list;





            var gongjie_list = [''];
            try {
                $('#gongjie_list tr').each(function (i) {
                    var tiaoid = $(this).find('.number').attr('tiaoid');
                    var houkoulei = $(this).find('.houkoulei').attr('houkoulei');
                    var youfee = $(this).find('.youfee').val();
                    var kouben = $(this).find('.kouben').val();
                    var kouli = $(this).find('.kouli').val();
                    var koufee = $(this).find('.koufee').val();
                    var kouxing = $(this).find('.kouxing').val();
                    var shoubiao = $(this).find('.shoubiao').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(data.field.isturn > 0){
                        if(!youfee){
                            throw new Error('第'+index+'行，请输入利息优惠');
                        }
                    }

                    gongjie_list.push({
                        tiaoid:tiaoid,
                        houkoulei:houkoulei,
                        youfee:youfee,
                        kouben:kouben,
                        kouli:kouli,
                        koufee:koufee,
                        kouxing:kouxing,
                        shoubiao:shoubiao,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".gongjie_list_info .listerror").find('span').text(e.message);
                $(".gongjie_list_info .listerror").show();
                return false;
            }
            $(".gongjie_list_info .listerror").hide();
            data.field.gongjie_list = gongjie_list;


            var kuaifei_list = [''];
            try {
                $('#kuaifei_list tr').each(function (i) {
                    var kuaiid = $(this).find('.enginname').attr('kuaiid');
                    var kuaitype = $(this).find('.enginname').attr('kuaitype');
                    var houkoulei = $(this).find('.houkoulei').attr('houkoulei');
                    var koufee = $(this).find('.koufee').val();
                    var kouxing = $(this).find('.kouxing').val();
                    var shoubiao = $(this).find('.shoubiao').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;


                    kuaifei_list.push({
                        kuaiid:kuaiid,
                        kuaitype:kuaitype,
                        houkoulei:houkoulei,
                        koufee:koufee,
                        kouxing:kouxing,
                        shoubiao:shoubiao,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".kuaifei_list_info .listerror").find('span').text(e.message);
                $(".kuaifei_list_info .listerror").show();
                return false;
            }
            $(".kuaifei_list_info .listerror").hide();
            data.field.kuaifei_list = kuaifei_list;


            var qifei_list = [''];
            try {
                $('#qifei_list tr').each(function (i) {
                    var enginid = $(this).find('.enginid').attr('enginid');
                    var houkoulei = $(this).find('.houkoulei').find('input').val();
                    var koufee = $(this).find('.koufee').val();
                    var kouxing = $(this).find('.kouxing').val();
                    var shoubiao = $(this).find('.shoubiao').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(!koufee){
                        throw new Error('第'+index+'行，请输入本次收取');
                    }
                    if(!kouxing){
                        throw new Error('第'+index+'行，请选择收取性质');
                    }

                    qifei_list.push({
                        enginid:enginid,
                        houkoulei:houkoulei,
                        koufee:koufee,
                        kouxing:kouxing,
                        shoubiao:shoubiao,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".qifei_list_info .listerror").find('span').text(e.message);
                $(".qifei_list_info .listerror").show();
                return false;
            }
            $(".qifei_list_info .listerror").hide();
            data.field.qifei_list = qifei_list;




            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            data = parseMoney(data);

            facade.ajax({url: ask_hou_gonghui_kou, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    facade.success("提交成功!");
                    setTimeout(() => {
                        parent.window.location.reload();
                    }, 1500);
                }
            });
            return false;
        });

    });



    function get_checkbox_value(dom) {
        var obj = document.getElementsByName(dom);
        var s = [];
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked){
                s.push(obj[i].value)
            }
        }
        return s;
    }


    $('#gongjie_list').on('input propertychange','.kouben,.kouli',function () {
        $('#gongjie_list tr').each(function (i) {
            var kouben = parseValidNum($(this).find('.kouben').val());
            var kouli = parseValidNum($(this).find('.kouli').val());
            var koufee = parseFloat(kouben) + parseFloat(kouli);
            $(this).find('.koufee').val(koufee);
        });
        jisuan_koufee_all();
    });




    $('#fuwu_list,#shuifei_list,#gongjie_list,#kuaifei_list,#qifei_list').on('input propertychange','.koufee',function () {
        jisuan_koufee_all();
    });

    function jisuan_koufee_all() {
        var allkoufee = 0;

        var arr = get_checkbox_value('koulei');
        if(in_array('fuwu', arr)){
            $('#fuwu_list tr').each(function (i) {
                var koufee = parseValidNum($(this).find('.koufee').val());
                allkoufee = parseFloat(allkoufee) + parseFloat(koufee);
            });
        }
        if(in_array('shuifei', arr)){
            $('#shuifei_list tr').each(function (i) {
                var koufee = parseValidNum($(this).find('.koufee').val());
                allkoufee = parseFloat(allkoufee) + parseFloat(koufee);
            });
        }
        if(in_array('gongjie', arr)){
            $('#gongjie_list tr').each(function (i) {
                var koufee = parseValidNum($(this).find('.koufee').val());
                allkoufee = parseFloat(allkoufee) + parseFloat(koufee);
            });
        }
        if(in_array('kuaifei', arr)){
            $('#kuaifei_list tr').each(function (i) {
                var koufee = parseValidNum($(this).find('.koufee').val());
                allkoufee = parseFloat(allkoufee) + parseFloat(koufee);
            });
        }
        if(in_array('qifei', arr)){
            $('#qifei_list tr').each(function (i) {
                var koufee = parseValidNum($(this).find('.koufee').val());
                allkoufee = parseFloat(allkoufee) + parseFloat(koufee);
            });
        }
        $("#koufee").val(parseFormatNum(allkoufee,2));
    }

    function update_refresh_row_func() {
        render_date();
        render_from();
        jisuan_koufee_all();
        $.each($("#list_list").children('tr'),function (key,val) {
            $(this).children('td:first-child').html(key+1);
        });
        setTimeout(function () {
            $(".short_table_list table tbody tr").click(function () {
                $(".short_table_list table tbody tr").removeClass('line-row');
                $(".short_table_list table tbody tr").attr('sle','');
                $(this).addClass('line-row');
                $(this).attr('sle','sle');
            });
        },1000);
    }



    function go_to_engin_xiang(){
        var enginid = get_choose_val('enginid');
        if(!enginid){
            facade.error("请先选择工程名称");return false;
        }
        openPage('../engin/xiang.php?id='+enginid);
    }
</script>
</body>
</html>
